<!DOCTYPE html>
<html lang="si">
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="මෙම දුම්රිය කෝරා දත්ත සමුදාය මත ප්රස්තාරය අවධානය ජාලය (GAT) වේ"/>

    <meta name="twitter:card" content="summary"/>
    <meta name="twitter:image:src" content="https://avatars1.githubusercontent.com/u/64068543?s=400&amp;v=4"/>
    <meta name="twitter:title" content="කෝරා දත්ත කට්ටලය මත ප්රස්තාරය අවධානය ජාලය (GAT) පුහුණු"/>
    <meta name="twitter:description" content="මෙම දුම්රිය කෝරා දත්ත සමුදාය මත ප්රස්තාරය අවධානය ජාලය (GAT) වේ"/>
    <meta name="twitter:site" content="@labmlai"/>
    <meta name="twitter:creator" content="@labmlai"/>

    <meta property="og:url" content="https://nn.labml.ai/graphs/gat/experiment.html"/>
    <meta property="og:title" content="කෝරා දත්ත කට්ටලය මත ප්රස්තාරය අවධානය ජාලය (GAT) පුහුණු"/>
    <meta property="og:image" content="https://avatars1.githubusercontent.com/u/64068543?s=400&amp;v=4"/>
    <meta property="og:site_name" content="කෝරා දත්ත කට්ටලය මත ප්රස්තාරය අවධානය ජාලය (GAT) පුහුණු"/>
    <meta property="og:type" content="object"/>
    <meta property="og:title" content="කෝරා දත්ත කට්ටලය මත ප්රස්තාරය අවධානය ජාලය (GAT) පුහුණු"/>
    <meta property="og:description" content="මෙම දුම්රිය කෝරා දත්ත සමුදාය මත ප්රස්තාරය අවධානය ජාලය (GAT) වේ"/>

    <title>කෝරා දත්ත කට්ටලය මත ප්රස්තාරය අවධානය ජාලය (GAT) පුහුණු</title>
    <link rel="shortcut icon" href="/icon.png"/>
    <link rel="stylesheet" href="../../pylit.css?v=1">
    <link rel="canonical" href="https://nn.labml.ai/graphs/gat/experiment.html"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css" integrity="sha384-zTROYFVGOfTw7JV7KUu8udsvW2fx4lWOsCEDqhBreBwlHI4ioVRtmIvEThzJHGET" crossorigin="anonymous">

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-4V3HC8HBLH"></script>
    <script>
        window.dataLayer = window.dataLayer || [];

        function gtag() {
            dataLayer.push(arguments);
        }

        gtag('js', new Date());

        gtag('config', 'G-4V3HC8HBLH');
    </script>
</head>
<body>
<div id='container'>
    <div id="background"></div>
    <div class='section'>
        <div class='docs'>
            <p>
                <a class="parent" href="/">home</a>
                <a class="parent" href="../index.html">graphs</a>
                <a class="parent" href="index.html">gat</a>
            </p>
            <p>
                <a href="https://github.com/labmlai/annotated_deep_learning_paper_implementations" target="_blank">
                    <img alt="Github"
                         src="https://img.shields.io/github/stars/labmlai/annotated_deep_learning_paper_implementations?style=social"
                         style="max-width:100%;"/></a>
                <a href="https://twitter.com/labmlai" rel="nofollow" target="_blank">
                    <img alt="Twitter"
                         src="https://img.shields.io/twitter/follow/labmlai?style=social"
                         style="max-width:100%;"/></a>
            </p>
            <p>
                <a href="https://github.com/labmlai/annotated_deep_learning_paper_implementations/tree/master/labml_nn/graphs/gat/experiment.py" target="_blank">
                    View code on Github</a>
            </p>
        </div>
    </div>
    <div class='section' id='section-0'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-0'>#</a>
            </div>
            <h1>කෝරාදත්ත කට්ටලය මත ප්රස්තාරය අවධානය ජාලය (GAT) පුහුණු</h1>
<p><a href="https://app.labml.ai/run/d6c636cadf3511eba2f1e707f612f95d"><img alt="View Run" src="https://img.shields.io/badge/labml-experiment-brightgreen"></a></p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">13</span><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Dict</span>
<span class="lineno">14</span>
<span class="lineno">15</span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="lineno">16</span><span class="kn">import</span> <span class="nn">torch</span>
<span class="lineno">17</span><span class="kn">from</span> <span class="nn">torch</span> <span class="kn">import</span> <span class="n">nn</span>
<span class="lineno">18</span>
<span class="lineno">19</span><span class="kn">from</span> <span class="nn">labml</span> <span class="kn">import</span> <span class="n">lab</span><span class="p">,</span> <span class="n">monit</span><span class="p">,</span> <span class="n">tracker</span><span class="p">,</span> <span class="n">experiment</span>
<span class="lineno">20</span><span class="kn">from</span> <span class="nn">labml.configs</span> <span class="kn">import</span> <span class="n">BaseConfigs</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span> <span class="n">calculate</span>
<span class="lineno">21</span><span class="kn">from</span> <span class="nn">labml.utils</span> <span class="kn">import</span> <span class="n">download</span>
<span class="lineno">22</span><span class="kn">from</span> <span class="nn">labml_helpers.device</span> <span class="kn">import</span> <span class="n">DeviceConfigs</span>
<span class="lineno">23</span><span class="kn">from</span> <span class="nn">labml_helpers.module</span> <span class="kn">import</span> <span class="n">Module</span>
<span class="lineno">24</span><span class="kn">from</span> <span class="nn">labml_nn.graphs.gat</span> <span class="kn">import</span> <span class="n">GraphAttentionLayer</span>
<span class="lineno">25</span><span class="kn">from</span> <span class="nn">labml_nn.optimizers.configs</span> <span class="kn">import</span> <span class="n">OptimizerConfigs</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-1'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-1'>#</a>
            </div>
            <h2><a href="https://linqs.soe.ucsc.edu/data">කෝරා දත්ත කට්ටලය</a></h2>
<p>කෝරා දත්ත කට්ටලය පර්යේෂණ පත්රිකා දත්ත කට්ටලයකි. සෑම කඩදාසි සඳහාම අපට ද්විමය අංග දෛශිකයක් ලබා දී ඇති අතර එය වචන ඇති බව පෙන්නුම් කරයි. සෑම කඩදාසියක්ම පන්ති 7 න් එකකට වර්ගීකරණය කර ඇත. දත්ත කට්ටලයට උපුටා දැක්වීමේ ජාලය ද ඇත.</p>
<p>පත්රිකා යනු ප්රස්ථාරයේ නෝඩ් වන අතර දාර උපුටා දැක්වීම් වේ.</p>
<p>කර්තව්යය වන්නේ නෝඩ් 7 පන්ති වලට විශේෂාංග දෛශික සහ උපුටා දැක්වීමේ ජාලය ආදානය ලෙස වර්ගීකරණය කිරීමයි.</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">28</span><span class="k">class</span> <span class="nc">CoraDataset</span><span class="p">:</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-2'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-2'>#</a>
            </div>
            <p>එක්එක් නෝඩය සඳහා ලේබල </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">43</span>    <span class="n">labels</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-3'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-3'>#</a>
            </div>
            <p>පන්තිනාම කට්ටලයක් සහ අද්විතීය පූර්ණ සංඛ්යා දර්ශකය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">45</span>    <span class="n">classes</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">int</span><span class="p">]</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-4'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-4'>#</a>
            </div>
            <p>සියලුමනෝඩ් සඳහා විශේෂාංග වාහකයන් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">47</span>    <span class="n">features</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-5'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-5'>#</a>
            </div>
            <p>දාරයේතොරතුරු සමඟ සම්බන්ධ වීමේ අනුකෘතිය. <code  class="highlight"><span></span><span class="n">adj_mat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span></code>
 සිට දාරයක් තිබේ <code  class="highlight"><span></span><span class="kc">True</span></code>
 <code  class="highlight"><span></span><span class="n">i</span></code>
 නම් <code  class="highlight"><span></span><span class="n">j</span></code>
. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">50</span>    <span class="n">adj_mat</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-6'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-6'>#</a>
            </div>
            <p> දත්තකට්ටලය බාගන්න</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">52</span>    <span class="nd">@staticmethod</span>
<span class="lineno">53</span>    <span class="k">def</span> <span class="nf">_download</span><span class="p">():</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-7'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-7'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">57</span>        <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">lab</span><span class="o">.</span><span class="n">get_data_path</span><span class="p">()</span> <span class="o">/</span> <span class="s1">&#39;cora&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
<span class="lineno">58</span>            <span class="n">download</span><span class="o">.</span><span class="n">download_file</span><span class="p">(</span><span class="s1">&#39;https://linqs-data.soe.ucsc.edu/public/lbc/cora.tgz&#39;</span><span class="p">,</span>
<span class="lineno">59</span>                                   <span class="n">lab</span><span class="o">.</span><span class="n">get_data_path</span><span class="p">()</span> <span class="o">/</span> <span class="s1">&#39;cora.tgz&#39;</span><span class="p">)</span>
<span class="lineno">60</span>            <span class="n">download</span><span class="o">.</span><span class="n">extract_tar</span><span class="p">(</span><span class="n">lab</span><span class="o">.</span><span class="n">get_data_path</span><span class="p">()</span> <span class="o">/</span> <span class="s1">&#39;cora.tgz&#39;</span><span class="p">,</span> <span class="n">lab</span><span class="o">.</span><span class="n">get_data_path</span><span class="p">())</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-8'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-8'>#</a>
            </div>
            <p> දත්තකට්ටලය පූරණය කරන්න</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">62</span>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">include_edges</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-9'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-9'>#</a>
            </div>
            <p>දාරඇතුළත් කළ යුතුද යන්න. මෙම අපි උපුටා දැක්වීමේ ජාලය නොසලකා නම් කොපමණ නිරවද්යතාව අහිමි වේ පරීක්ෂා වේ. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">69</span>        <span class="bp">self</span><span class="o">.</span><span class="n">include_edges</span> <span class="o">=</span> <span class="n">include_edges</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-10'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-10'>#</a>
            </div>
            <p>බාගතදත්ත කට්ටලය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">72</span>        <span class="bp">self</span><span class="o">.</span><span class="n">_download</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-11'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-11'>#</a>
            </div>
            <p>කඩදාසිහැඳුනුම්පත්, විශේෂාංග දෛශික සහ ලේබල කියවන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">75</span>        <span class="k">with</span> <span class="n">monit</span><span class="o">.</span><span class="n">section</span><span class="p">(</span><span class="s1">&#39;Read content file&#39;</span><span class="p">):</span>
<span class="lineno">76</span>            <span class="n">content</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">lab</span><span class="o">.</span><span class="n">get_data_path</span><span class="p">()</span> <span class="o">/</span> <span class="s1">&#39;cora/cora.content&#39;</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">(</span><span class="nb">str</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-12'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-12'>#</a>
            </div>
            <p>උපුටාදැක්වීම් පූරණය කරන්න, එය නිඛිල යුගල ලැයිස්තුවකි. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">78</span>        <span class="k">with</span> <span class="n">monit</span><span class="o">.</span><span class="n">section</span><span class="p">(</span><span class="s1">&#39;Read citations file&#39;</span><span class="p">):</span>
<span class="lineno">79</span>            <span class="n">citations</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">genfromtxt</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">lab</span><span class="o">.</span><span class="n">get_data_path</span><span class="p">()</span> <span class="o">/</span> <span class="s1">&#39;cora/cora.cites&#39;</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-13'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-13'>#</a>
            </div>
            <p>විශේෂාංගදෛශික ලබා ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">82</span>        <span class="n">features</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">content</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-14'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-14'>#</a>
            </div>
            <p>විශේෂාංගදෛශික සාමාන්යකරණය කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">84</span>        <span class="bp">self</span><span class="o">.</span><span class="n">features</span> <span class="o">=</span> <span class="n">features</span> <span class="o">/</span> <span class="n">features</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">keepdim</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-15'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-15'>#</a>
            </div>
            <p>පන්තිනාම ලබා ගන්න සහ ඒ එක් එක් සඳහා අද්විතීය පූර්ණ සංඛ්යාවක් පවරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">87</span>        <span class="bp">self</span><span class="o">.</span><span class="n">classes</span> <span class="o">=</span> <span class="p">{</span><span class="n">s</span><span class="p">:</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">s</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">content</span><span class="p">[:,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]))}</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-16'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-16'>#</a>
            </div>
            <p>එමලේබල් එම නිඛිල ලෙස ලබා ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">89</span>        <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">classes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">content</span><span class="p">[:,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">long</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-17'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-17'>#</a>
            </div>
            <p>කඩදාසිහැඳුනුම්පත් ලබා ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">92</span>        <span class="n">paper_ids</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">content</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-18'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-18'>#</a>
            </div>
            <p>කඩදාසිහැඳුනුම්පතේ සිට දර්ශකය දක්වා සිතියම </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">94</span>        <span class="n">ids_to_idx</span> <span class="o">=</span> <span class="p">{</span><span class="n">id_</span><span class="p">:</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">id_</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">paper_ids</span><span class="p">)}</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-19'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-19'>#</a>
            </div>
            <p>හිස්adjacency න්යාසය - අනන්යතා අනුකෘතියක් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">97</span>        <span class="bp">self</span><span class="o">.</span><span class="n">adj_mat</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">labels</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">bool</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-20'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-20'>#</a>
            </div>
            <p>මෙමadjacency න්යාසය තුළ උපුටා දැක්වීම් සලකුණු </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">100</span>        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">include_edges</span><span class="p">:</span>
<span class="lineno">101</span>            <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">citations</span><span class="p">:</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-21'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-21'>#</a>
            </div>
            <p>කඩදාසිදර්ශක යුගලය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">103</span>                <span class="n">e1</span><span class="p">,</span> <span class="n">e2</span> <span class="o">=</span> <span class="n">ids_to_idx</span><span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="mi">0</span><span class="p">]],</span> <span class="n">ids_to_idx</span><span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-22'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-22'>#</a>
            </div>
            <p>අපිසමමිතික ප්රස්තාරය ඉදි, එහිදී කඩදාසි <span ><span class="katex"><span aria-hidden="true" class="katex-html"><span class="base"><span class="strut" style="height:0.65952em;vertical-align:0em;"></span><span class="mord coloredeq eqa" style=""><span class="mord mathnormal" style="">i</span></span></span></span></span></span> යොමු කඩදාසි නම් <span ><span class="katex"><span aria-hidden="true" class="katex-html"><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord coloredeq eqb" style=""><span class="mord mathnormal" style="margin-right:0.05724em">j</span></span></span></span></span></span> අපි සිට <span ><span class="katex"><span aria-hidden="true" class="katex-html"><span class="base"><span class="strut" style="height:0.65952em;vertical-align:0em;"></span><span class="mord coloredeq eqa" style=""><span class="mord mathnormal" style="">i</span></span></span></span></span></span> adge තැනින් <span ><span class="katex"><span aria-hidden="true" class="katex-html"><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord coloredeq eqb" style=""><span class="mord mathnormal" style="margin-right:0.05724em">j</span></span></span></span></span></span> මෙන්ම සිට අද්දර <span ><span class="katex"><span aria-hidden="true" class="katex-html"><span class="base"><span class="strut" style="height:0.85396em;vertical-align:-0.19444em;"></span><span class="mord coloredeq eqb" style=""><span class="mord mathnormal" style="margin-right:0.05724em">j</span></span></span></span></span></span> කිරීමට <span ><span class="katex"><span aria-hidden="true" class="katex-html"><span class="base"><span class="strut" style="height:0.65952em;vertical-align:0em;"></span><span class="mord coloredeq eqa" style=""><span class="mord mathnormal" style="">i</span></span></span></span></span></span>. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">107</span>                <span class="bp">self</span><span class="o">.</span><span class="n">adj_mat</span><span class="p">[</span><span class="n">e1</span><span class="p">][</span><span class="n">e2</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="lineno">108</span>                <span class="bp">self</span><span class="o">.</span><span class="n">adj_mat</span><span class="p">[</span><span class="n">e2</span><span class="p">][</span><span class="n">e1</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-23'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-23'>#</a>
            </div>
            <h2>ප්රස්තාරයඅවධානය ජාලය (GAT)</h2>
<p>මෙමප්රස්තාර අවධානය ජාලය <a href="index.html">ප්රස්තාරය අවධානය ස්ථර</a>දෙකක් ඇත. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">111</span><span class="k">class</span> <span class="nc">GAT</span><span class="p">(</span><span class="n">Module</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-24'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-24'>#</a>
            </div>
            <ul><li><code  class="highlight"><span></span><span class="n">in_features</span></code>
 node එකක් මතම ඊට අදාල විශේෂාංග සංඛ්යාව වේ </li>
<li><code  class="highlight"><span></span><span class="n">n_hidden</span></code>
 පළමු ප්රස්තාරය අවධානය ස්ථරය ලක්ෂණ සංඛ්යාව වේ </li>
<li><code  class="highlight"><span></span><span class="n">n_classes</span></code>
 යනු පන්ති ගණන </li>
<li><code  class="highlight"><span></span><span class="n">n_heads</span></code>
 ප්රස්ථාර අවධානය ස්ථර වල හිස් ගණන </li>
<li><code  class="highlight"><span></span><span class="n">dropout</span></code>
 අතහැර දැමීමේ සම්භාවිතාව</li></ul>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">118</span>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">in_features</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">n_hidden</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">n_classes</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">n_heads</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">dropout</span><span class="p">:</span> <span class="nb">float</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-25'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-25'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">126</span>        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-26'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-26'>#</a>
            </div>
            <p>අපිහිස් concatenate එහිදී පළමු ප්රස්තාරය අවධානය ස්ථරය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">129</span>        <span class="bp">self</span><span class="o">.</span><span class="n">layer1</span> <span class="o">=</span> <span class="n">GraphAttentionLayer</span><span class="p">(</span><span class="n">in_features</span><span class="p">,</span> <span class="n">n_hidden</span><span class="p">,</span> <span class="n">n_heads</span><span class="p">,</span> <span class="n">is_concat</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dropout</span><span class="o">=</span><span class="n">dropout</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-27'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-27'>#</a>
            </div>
            <p>පළමුප්රස්ථාර අවධානය ස්ථරයෙන් පසු සක්රිය කිරීමේ කාර්යය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">131</span>        <span class="bp">self</span><span class="o">.</span><span class="n">activation</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">ELU</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-28'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-28'>#</a>
            </div>
            <p>අපිහිස් සාමාන්යය එහිදී අවසන් ප්රස්තාරය අවධානය ස්ථරය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">133</span>        <span class="bp">self</span><span class="o">.</span><span class="n">output</span> <span class="o">=</span> <span class="n">GraphAttentionLayer</span><span class="p">(</span><span class="n">n_hidden</span><span class="p">,</span> <span class="n">n_classes</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">is_concat</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">dropout</span><span class="o">=</span><span class="n">dropout</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-29'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-29'>#</a>
            </div>
            <p>හැලීම </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">135</span>        <span class="bp">self</span><span class="o">.</span><span class="n">dropout</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">Dropout</span><span class="p">(</span><span class="n">dropout</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-30'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-30'>#</a>
            </div>
            <ul><li><code  class="highlight"><span></span><span class="n">x</span></code>
 හැඩයේ ලක්ෂණ දෛශික වේ <code  class="highlight"><span></span><span class="p">[</span><span class="n">n_nodes</span><span class="p">,</span> <span class="n">in_features</span><span class="p">]</span></code>
 </li>
<li><code  class="highlight"><span></span><span class="n">adj_mat</span></code>
 යනු ආකෘතියේ අනුකෘතියේ අනුකෘතිය <code  class="highlight"><span></span><span class="p">[</span><span class="n">n_nodes</span><span class="p">,</span> <span class="n">n_nodes</span><span class="p">,</span> <span class="n">n_heads</span><span class="p">]</span></code>
 හෝ <code  class="highlight"><span></span><span class="p">[</span><span class="n">n_nodes</span><span class="p">,</span> <span class="n">n_nodes</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span></code>
</li></ul>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">137</span>    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">adj_mat</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-31'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-31'>#</a>
            </div>
            <p>ආදානයටඅතහැර දැමීම යොදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">144</span>        <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dropout</span><span class="p">(</span><span class="n">x</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-32'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-32'>#</a>
            </div>
            <p>පළමුප්රස්ථාර අවධානය ස්ථරය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">146</span>        <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">layer1</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">adj_mat</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-33'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-33'>#</a>
            </div>
            <p>සක්රියකිරීමේ කාර්යය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">148</span>        <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">activation</span><span class="p">(</span><span class="n">x</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-34'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-34'>#</a>
            </div>
            <p>හැලීම </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">150</span>        <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dropout</span><span class="p">(</span><span class="n">x</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-35'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-35'>#</a>
            </div>
            <p>පිවිසුම්සඳහා ප්රතිදාන ස්ථරය (සක්රිය කිරීමකින් තොරව) </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">152</span>        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">adj_mat</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-36'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-36'>#</a>
            </div>
            <p> නිරවද්යතාවගණනය කිරීම සඳහා සරල ශ්රිතයක්</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">155</span><span class="k">def</span> <span class="nf">accuracy</span><span class="p">(</span><span class="n">output</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">labels</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-37'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-37'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">159</span>    <span class="k">return</span> <span class="n">output</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">dim</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">eq</span><span class="p">(</span><span class="n">labels</span><span class="p">)</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">labels</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-38'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-38'>#</a>
            </div>
            <h2>වින්යාසකිරීම්</h2>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">162</span><span class="k">class</span> <span class="nc">Configs</span><span class="p">(</span><span class="n">BaseConfigs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-39'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-39'>#</a>
            </div>
            <p>ආකෘතිය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">168</span>    <span class="n">model</span><span class="p">:</span> <span class="n">GAT</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-40'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-40'>#</a>
            </div>
            <p>පුහුණුකිරීමට නෝඩ් ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">170</span>    <span class="n">training_samples</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">500</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-41'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-41'>#</a>
            </div>
            <p>ආදානයේනෝඩයකට විශේෂාංග ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">172</span>    <span class="n">in_features</span><span class="p">:</span> <span class="nb">int</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-42'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-42'>#</a>
            </div>
            <p>පළමුප්රස්තාරයේ අවධානය ස්ථරයේ විශේෂාංග ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">174</span>    <span class="n">n_hidden</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">64</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-43'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-43'>#</a>
            </div>
            <p>හිස්ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">176</span>    <span class="n">n_heads</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">8</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-44'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-44'>#</a>
            </div>
            <p>වර්ගීකරණයසඳහා පන්ති ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">178</span>    <span class="n">n_classes</span><span class="p">:</span> <span class="nb">int</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-45'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-45'>#</a>
            </div>
            <p>අතහැරදැමීමේ සම්භාවිතාව </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">180</span>    <span class="n">dropout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.6</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-46'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-46'>#</a>
            </div>
            <p>උපුටාදැක්වීමේ ජාලය ඇතුළත් කළ යුතුද යන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">182</span>    <span class="n">include_edges</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-47'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-47'>#</a>
            </div>
            <p>දත්තකට්ටලය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">184</span>    <span class="n">dataset</span><span class="p">:</span> <span class="n">CoraDataset</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-48'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-48'>#</a>
            </div>
            <p>පුහුණුපුනරාවර්තන ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">186</span>    <span class="n">epochs</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1_000</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-49'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-49'>#</a>
            </div>
            <p>පාඩුශ්රිතය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">188</span>    <span class="n">loss_func</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">CrossEntropyLoss</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-50'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-50'>#</a>
            </div>
            <p>පුහුණුකිරීමට උපාංගය</p>
<p>මෙයඋපාංගය සඳහා වින්යාස නිර්මාණය කරයි, එවිට අපට වින්යාස අගයක් පසු කිරීමෙන් උපාංගය වෙනස් කළ හැකිය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">193</span>    <span class="n">device</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">device</span> <span class="o">=</span> <span class="n">DeviceConfigs</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-51'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-51'>#</a>
            </div>
            <p>ප්රශස්තකරණය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">195</span>    <span class="n">optimizer</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">Adam</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-52'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-52'>#</a>
            </div>
            <h3>පුහුණුලූපය</h3>
<p>දත්තසමුදාය කුඩා බැවින් අපි පූර්ණ කණ්ඩායම් පුහුණුව කරන්නෙමු. අප නියැදිය හා පුහුණු කිරීමට නම්, එක් එක් පුහුණු පියවර සඳහා නෝඩ් කට්ටලයක් සාම්පල ලබා ගත යුතු අතර එම තෝරාගත් නෝඩ් හරහා විහිදෙන දාර සමඟ. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">197</span>    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-53'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-53'>#</a>
            </div>
            <p>විශේෂාංගදෛශික උපාංගයට ගෙනයන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">207</span>        <span class="n">features</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">features</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-54'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-54'>#</a>
            </div>
            <p>ලේබලඋපාංගයට ගෙනයන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">209</span>        <span class="n">labels</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">labels</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-55'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-55'>#</a>
            </div>
            <p>උපකරණයටඅනුකෘතිය ගෙන යන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">211</span>        <span class="n">edges_adj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">adj_mat</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-56'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-56'>#</a>
            </div>
            <p>හිස්සඳහා හිස් තෙවන මානයක් එක් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">213</span>        <span class="n">edges_adj</span> <span class="o">=</span> <span class="n">edges_adj</span><span class="o">.</span><span class="n">unsqueeze</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-57'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-57'>#</a>
            </div>
            <p>අහඹුදර්ශක </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">216</span>        <span class="n">idx_rand</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">randperm</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">labels</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-58'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-58'>#</a>
            </div>
            <p>පුහුණුවසඳහා නෝඩ් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">218</span>        <span class="n">idx_train</span> <span class="o">=</span> <span class="n">idx_rand</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">training_samples</span><span class="p">]</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-59'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-59'>#</a>
            </div>
            <p>වලංගුකිරීම සඳහා නෝඩ් </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">220</span>        <span class="n">idx_valid</span> <span class="o">=</span> <span class="n">idx_rand</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">training_samples</span><span class="p">:]</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-60'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-60'>#</a>
            </div>
            <p>පුහුණුලූපය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">223</span>        <span class="k">for</span> <span class="n">epoch</span> <span class="ow">in</span> <span class="n">monit</span><span class="o">.</span><span class="n">loop</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">epochs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-61'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-61'>#</a>
            </div>
            <p>පුහුණුමාදිලියට ආකෘතිය සකසන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">225</span>            <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-62'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-62'>#</a>
            </div>
            <p>සියලුමඅනුක්රමික ශුන්ය කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">227</span>            <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">zero_grad</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-63'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-63'>#</a>
            </div>
            <p>ආකෘතියතක්සේරු කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">229</span>            <span class="n">output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">edges_adj</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-64'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-64'>#</a>
            </div>
            <p>පුහුණුනෝඩ් සඳහා අලාභය ලබා ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">231</span>            <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_func</span><span class="p">(</span><span class="n">output</span><span class="p">[</span><span class="n">idx_train</span><span class="p">],</span> <span class="n">labels</span><span class="p">[</span><span class="n">idx_train</span><span class="p">])</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-65'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-65'>#</a>
            </div>
            <p>අනුක්රමිකගණනය කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">233</span>            <span class="n">loss</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-66'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-66'>#</a>
            </div>
            <p>ප්රශස්තිකරණපියවර ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">235</span>            <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">step</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-67'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-67'>#</a>
            </div>
            <p>අලාභයලොග් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">237</span>            <span class="n">tracker</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;loss.train&#39;</span><span class="p">,</span> <span class="n">loss</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-68'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-68'>#</a>
            </div>
            <p>නිරවද්යතාවයලොග් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">239</span>            <span class="n">tracker</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;accuracy.train&#39;</span><span class="p">,</span> <span class="n">accuracy</span><span class="p">(</span><span class="n">output</span><span class="p">[</span><span class="n">idx_train</span><span class="p">],</span> <span class="n">labels</span><span class="p">[</span><span class="n">idx_train</span><span class="p">]))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-69'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-69'>#</a>
            </div>
            <p>වලංගුකිරීම සඳහා ඇගයීමේ ප්රකාරයට සකසන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">242</span>            <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">eval</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-70'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-70'>#</a>
            </div>
            <p>අනුක්රමිකගණනය කිරීමට අවශ්ය නැත </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">245</span>            <span class="k">with</span> <span class="n">torch</span><span class="o">.</span><span class="n">no_grad</span><span class="p">():</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-71'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-71'>#</a>
            </div>
            <p>ආකෘතියනැවත ඇගයීමට ලක් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">247</span>                <span class="n">output</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">edges_adj</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-72'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-72'>#</a>
            </div>
            <p>වලංගුකිරීමේ නෝඩ් සඳහා අලාභය ගණනය කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">249</span>                <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_func</span><span class="p">(</span><span class="n">output</span><span class="p">[</span><span class="n">idx_valid</span><span class="p">],</span> <span class="n">labels</span><span class="p">[</span><span class="n">idx_valid</span><span class="p">])</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-73'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-73'>#</a>
            </div>
            <p>අලාභයලොග් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">251</span>                <span class="n">tracker</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;loss.valid&#39;</span><span class="p">,</span> <span class="n">loss</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-74'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-74'>#</a>
            </div>
            <p>නිරවද්යතාවයලොග් කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">253</span>                <span class="n">tracker</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;accuracy.valid&#39;</span><span class="p">,</span> <span class="n">accuracy</span><span class="p">(</span><span class="n">output</span><span class="p">[</span><span class="n">idx_valid</span><span class="p">],</span> <span class="n">labels</span><span class="p">[</span><span class="n">idx_valid</span><span class="p">]))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-75'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-75'>#</a>
            </div>
            <p>ලොග්සුරකින්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">256</span>            <span class="n">tracker</span><span class="o">.</span><span class="n">save</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-76'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-76'>#</a>
            </div>
            <p> කෝරාදත්ත කට්ටලය සාදන්න</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">259</span><span class="nd">@option</span><span class="p">(</span><span class="n">Configs</span><span class="o">.</span><span class="n">dataset</span><span class="p">)</span>
<span class="lineno">260</span><span class="k">def</span> <span class="nf">cora_dataset</span><span class="p">(</span><span class="n">c</span><span class="p">:</span> <span class="n">Configs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-77'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-77'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">264</span>    <span class="k">return</span> <span class="n">CoraDataset</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">include_edges</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-78'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-78'>#</a>
            </div>
            <p>පන්තිගණන ලබා ගන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">268</span><span class="n">calculate</span><span class="p">(</span><span class="n">Configs</span><span class="o">.</span><span class="n">n_classes</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">c</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">classes</span><span class="p">))</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-79'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-79'>#</a>
            </div>
            <p>ආදානයේවිශේෂාංග ගණන </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">270</span><span class="n">calculate</span><span class="p">(</span><span class="n">Configs</span><span class="o">.</span><span class="n">in_features</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">c</span><span class="p">:</span> <span class="n">c</span><span class="o">.</span><span class="n">dataset</span><span class="o">.</span><span class="n">features</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-80'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-80'>#</a>
            </div>
            <p> GATආකෘතිය සාදන්න</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">273</span><span class="nd">@option</span><span class="p">(</span><span class="n">Configs</span><span class="o">.</span><span class="n">model</span><span class="p">)</span>
<span class="lineno">274</span><span class="k">def</span> <span class="nf">gat_model</span><span class="p">(</span><span class="n">c</span><span class="p">:</span> <span class="n">Configs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-81'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-81'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">278</span>    <span class="k">return</span> <span class="n">GAT</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">in_features</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">n_hidden</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">n_classes</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">n_heads</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">dropout</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">device</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-82'>
        <div class='docs doc-strings'>
            <div class='section-link'>
                <a href='#section-82'>#</a>
            </div>
            <p> වින්යාසගතකළ හැකි ප්රශස්තකරණය</p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">281</span><span class="nd">@option</span><span class="p">(</span><span class="n">Configs</span><span class="o">.</span><span class="n">optimizer</span><span class="p">)</span>
<span class="lineno">282</span><span class="k">def</span> <span class="nf">_optimizer</span><span class="p">(</span><span class="n">c</span><span class="p">:</span> <span class="n">Configs</span><span class="p">):</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-83'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-83'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">286</span>    <span class="n">opt_conf</span> <span class="o">=</span> <span class="n">OptimizerConfigs</span><span class="p">()</span>
<span class="lineno">287</span>    <span class="n">opt_conf</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">parameters</span><span class="p">()</span>
<span class="lineno">288</span>    <span class="k">return</span> <span class="n">opt_conf</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-84'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-84'>#</a>
            </div>
            
        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">291</span><span class="k">def</span> <span class="nf">main</span><span class="p">():</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-85'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-85'>#</a>
            </div>
            <p>වින්යාසයන්සාදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">293</span>    <span class="n">conf</span> <span class="o">=</span> <span class="n">Configs</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-86'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-86'>#</a>
            </div>
            <p>අත්හදාබැලීමක් සාදන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">295</span>    <span class="n">experiment</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;gat&#39;</span><span class="p">)</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-87'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-87'>#</a>
            </div>
            <p>වින්යාසයන්ගණනය කරන්න. </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">297</span>    <span class="n">experiment</span><span class="o">.</span><span class="n">configs</span><span class="p">(</span><span class="n">conf</span><span class="p">,</span> <span class="p">{</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-88'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-88'>#</a>
            </div>
            <p>ආදම්ප්රශස්තකරණය </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">299</span>        <span class="s1">&#39;optimizer.optimizer&#39;</span><span class="p">:</span> <span class="s1">&#39;Adam&#39;</span><span class="p">,</span>
<span class="lineno">300</span>        <span class="s1">&#39;optimizer.learning_rate&#39;</span><span class="p">:</span> <span class="mf">5e-3</span><span class="p">,</span>
<span class="lineno">301</span>        <span class="s1">&#39;optimizer.weight_decay&#39;</span><span class="p">:</span> <span class="mf">5e-4</span><span class="p">,</span>
<span class="lineno">302</span>    <span class="p">})</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-89'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-89'>#</a>
            </div>
            <p>අත්හදාබැලීම ආරම්භ කර නරඹන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">305</span>    <span class="k">with</span> <span class="n">experiment</span><span class="o">.</span><span class="n">start</span><span class="p">():</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-90'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-90'>#</a>
            </div>
            <p>පුහුණුවක්රියාත්මක කරන්න </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">307</span>        <span class="n">conf</span><span class="o">.</span><span class="n">run</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='section' id='section-91'>
        <div class='docs'>
            <div class='section-link'>
                <a href='#section-91'>#</a>
            </div>
            <p> </p>

        </div>
        <div class='code'>
            <div class="highlight"><pre><span class="lineno">311</span><span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
<span class="lineno">312</span>    <span class="n">main</span><span class="p">()</span></pre></div>
        </div>
    </div>
    <div class='footer'>
        <a href="https://papers.labml.ai">Trending Research Papers</a>
        <a href="https://labml.ai">labml.ai</a>
    </div>
</div>
<script src=../../interactive.js?v=1"></script>
<script>
    function handleImages() {
        var images = document.querySelectorAll('p>img')

        for (var i = 0; i < images.length; ++i) {
            handleImage(images[i])
        }
    }

    function handleImage(img) {
        img.parentElement.style.textAlign = 'center'

        var modal = document.createElement('div')
        modal.id = 'modal'

        var modalContent = document.createElement('div')
        modal.appendChild(modalContent)

        var modalImage = document.createElement('img')
        modalContent.appendChild(modalImage)

        var span = document.createElement('span')
        span.classList.add('close')
        span.textContent = 'x'
        modal.appendChild(span)

        img.onclick = function () {
            console.log('clicked')
            document.body.appendChild(modal)
            modalImage.src = img.src
        }

        span.onclick = function () {
            document.body.removeChild(modal)
        }
    }

    handleImages()
</script>
</body>
</html>